using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class Name
    {
        internal Database db;
        private int itemId;
        private string itemName;
        private int categoryId;
        private int groupId;
        private int typeId;

        private EveObject item;
        private Category category;
        private Group group;
        private Type type;

        public EveObject Item
        {
            get
            {
                if (item == null)
                    item = EveData.GetObject(db, itemId);
                return item;
            }
        }
        public string Text
        {
            get { return itemName; }
        }
        public Category Category
        {
            get
            {
                if (category == null)
                    category = new Category(db, categoryId);
                return category;
            }
        }
        public Group Group
        {
            get
            {
                if (group == null)
                    group = new Group(db, groupId);
                return group;
            }
        }
        public Type Type
        {
            get
            {
                if (type == null)
                    type = new Type(db, typeId);
                return type;
            }
        }

        internal Name(DbDataRow dr)
        {
            this.db = dr.Database;
            Fill(dr);
        }
        internal Name(Database db, int id)
        {
            this.db = db;
            Fill(db.ExecuteSingle("SELECT * FROM eveNames WHERE itemID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            itemId = dr["itemID"];
            itemName = dr["itemName"];
            categoryId = dr["categoryID"];
            groupId = dr["groupID"];
            typeId = dr["typeID"];
        }
    }
}
